﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Permissions;


namespace RH.EBS.Core.Repository.DBUtility
{
    [Serializable]
    public class SqlItemArray : ISerializable
    {
        List<SqlItem> m_sqlItemList = new List<SqlItem>();

        public SqlItemArray()
        {
        }

        public List<SqlItem> SqlItemList
        {
            get
            {
                return m_sqlItemList;
            }
            set
            {
                m_sqlItemList = value;
            }
        }

        public void AppendSqlItem(SqlItem item)
        {
            m_sqlItemList.Add(item);
        }

        protected SqlItemArray(SerializationInfo info, StreamingContext context)
        {
            int sql_count = info.GetInt32("sql_count");
            for (int i = 0; i < sql_count; i++)
            {
                m_sqlItemList.Add((SqlItem)info.GetValue(i.ToString(), typeof(SqlItem)));
            }
        }

        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("sql_count", m_sqlItemList.Count);
            for (int i = 0; i < m_sqlItemList.Count; i++)
            {
                info.AddValue(i.ToString(), m_sqlItemList[i], typeof(SqlItem));
            }
        }
    }
}
